import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
// import 'package:kerala_lottery/tools/KL_Generator.dart';

import '../tools/FL_NumberGenerator.dart';
import '../tools/KL_Generator.dart';
import '../tools/models/KaL_DataViewModels.dart';

enum ViewType {
  type_RegularNumbersFrequency,
  type_SkippedNumbersAnalytics,
  type_ConsecutiveNumbersAnalytics,
  type_SumsofNumbers,
  type_EvenOddofNumbers,
}

class EJ_generaAnalyticsView extends StatefulWidget {
  EJ_generaAnalyticsView({
    super.key,
    required this.dataType,
    this.Numbers,
  });
  ViewType dataType;
  List? Numbers;

  @override
  State<EJ_generaAnalyticsView> createState() => _EJ_generaAnalyticsViewState();
}

class _EJ_generaAnalyticsViewState extends State<EJ_generaAnalyticsView> {
  late var _lottoResult = [];
  // late var _generatorNumbers = [];
  int _probability = 0;
  var _probabilityLable = '';
  var _progress = 0.0;
  late ViewType _type;
  late String _title = '';
  late String _detailString = '';
  late Color _valueColor = Colors.red; //进度颜色

  _configTitleAndColor() {
    if (_probability >= 43 && _probability < 55) {
      _probabilityLable = 'POOR';
      _valueColor = HexColor('#D54941');
    } else if (_probability >= 55 && _probability < 70) {
      _probabilityLable = 'AVERAGE';
      _valueColor = HexColor('#E37318');
    } else if (_probability >= 70) {
      _probabilityLable = 'GOOD';
      _valueColor = Colors.green;
    }
    _progress = _probability / 100;
  }

  _configTitle(ViewType type) {
    switch (type) {
      case ViewType.type_RegularNumbersFrequency:
        {
          _title = 'Numbers Frequency';
          // _detailString = _getRegularNumbersFrequency();
          // _detailString =
          //     FLNumberGenerator.instance.RegularNumbersFrequencyDetailString;
          // _probability =
          //     FLNumberGenerator.instance.RegularNumbersFrequencyScore;

          ///
          _detailString = KL_Generator.instance.NumbersFrequencyDetailString;
          _probability = KL_Generator.instance.NumbersFrequencyScore;
          _configTitleAndColor();

          // _detailString =
          //     '你选择的号码当中有70%在近期出现频率高于平均值：6(7%), 12(4%), 25(8%), 31(5%), 48(8%)，平均值10%';
        }
        break;
      case ViewType.type_SkippedNumbersAnalytics:
        {
          _title = 'Skipped Numbers Analytics';
          // _detailString = _getSkippedNumbersAnalytics();
          // _detailString =
          //     FLNumberGenerator.instance.SkippedNumbersAnalyticsDetailString;
          // _probability =
          //     FLNumberGenerator.instance.SkippedNumbersAnalyticsScore;

          ///
          _detailString =
              KL_Generator.instance.SkippedNumbersAnalyticsDetailString;
          _probability = KL_Generator.instance.SkippedNumbersAnalyticsScore;

          _configTitleAndColor();
          // _detailString =
          // '你选择的号码当中有70%遗漏期数高于平均值：6(13 Draws), 12(12 Draws), 25(0 Draws), 31(2 Draws), 48(8 Draws)，平均值10 Draws';
        }
        break;
      case ViewType.type_ConsecutiveNumbersAnalytics:
        {
          _title = 'Consecutive Numbers Analytics';
          // _detailString = _ConsecutiveNumbersAnalytics();
          // _detailString =
          //     FLNumberGenerator.instance.ConsecutiveNumbersAnalyticsDetail;
          // _probability =
          //     FLNumberGenerator.instance.ConsecutiveNumbersAnalyticsScore;

          ///
          _detailString =
              KL_Generator.instance.ConsecutiveNumbersAnalyticsDetail;
          _probability = KL_Generator.instance.ConsecutiveNumbersAnalyticsScore;
          _configTitleAndColor();
          // _detailString = '你选择的号码当中有2个号码上期曾经开出，6(2 Draws), 25(1 Draws)';
        }
        break;
      case ViewType.type_SumsofNumbers:
        {
          _title = 'Sums of Numbers';
          // _detailString = _getNumbersTotle();
          // _detailString = FLNumberGenerator.instance.SumsOfNumbersDetailString;
          // _probability = FLNumberGenerator.instance.SumsOfNumbersScore;

          ///
          _detailString = KL_Generator.instance.SumsOfNumbersDetailString;
          _probability = KL_Generator.instance.SumsOfNumbersScore;
          _configTitleAndColor();
        }
        break;
      case ViewType.type_EvenOddofNumbers:
        {
          _title = 'Even/Odd of Numbers';
          // _detailString = _getOddEvenNumber();
          // _detailString =
          //     FLNumberGenerator.instance.EventOddOfNumbersDetailString;
          // _probability = FLNumberGenerator.instance.EventOddOfNumbersScore;

          ///
          _detailString = KL_Generator.instance.EventOddOfNumbersDetailString;
          _probability = KL_Generator.instance.EventOddOfNumbersScore;
          _configTitleAndColor();
        }
        break;
      default:
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _lottoResult = KaL_DataViewModels().EJ_lottoResults;
    _type = widget.dataType;
  }

  @override
  Widget build(BuildContext context) {
    // _generatorNumbers = widget.Numbers!;
    _configTitle(_type);

    return Container(
      margin: const EdgeInsets.only(bottom: 15),
      decoration: BoxDecoration(
        color: HexColor('#f5f5f5'),
        borderRadius: const BorderRadius.all(Radius.circular(10)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.2), // 阴影颜色
            spreadRadius: 1, // 扩散半径
            blurRadius: 10, // 模糊半径
            offset: Offset(0, 1), // 阴影偏移
          ),
        ],
      ),
      child: Row(
        children: [
          Expanded(
              child: Container(
            margin: const EdgeInsets.all(15),
            // color: Colors.red,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  _title,
                  style: TextStyle(
                      fontSize: 14,
                      fontWeight: FontWeight.w600,
                      color: HexColor('#333333')),
                ),
                const SizedBox(height: 5),
                Text(
                  _detailString,
                  style: TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w400,
                    color: HexColor('#666666'),
                  ),
                )
              ],
            ),
          )),
          Container(
            margin: const EdgeInsets.only(top: 10, bottom: 10),
            alignment: Alignment.center,
            // color: Colors.yellow,
            width: 80,
            child: Column(
              children: [
                Container(
                  // alignment: Alignment.center,
                  // color: Colors.yellow,
                  width: 35,
                  height: 35,
                  child: Stack(
                    alignment: Alignment.center,
                    children: [
                      Text(
                        '$_probability',
                        style: const TextStyle(
                            fontSize: 13, fontWeight: FontWeight.w600),
                      ),
                      CircularProgressIndicator(
                        backgroundColor: HexColor('#e7e7e7'),
                        valueColor: AlwaysStoppedAnimation(_valueColor),
                        strokeWidth: 3.0,
                        strokeCap: StrokeCap.round,
                        value: _progress,
                      ),
                    ],
                  ),
                ),
                const SizedBox(height: 5),
                Text(
                  _probabilityLable,
                  textAlign: TextAlign.center,
                  style: const TextStyle(
                      fontWeight: FontWeight.w600, fontSize: 12),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
